<html lang="en">
<head>
    <meta charset="utf-8">
    <title>版本浏览</title>
    <link href="/static/css/start/jquery-ui-1.10.4.custom.css" rel="stylesheet">
    <link href="/static/css/box.css" rel="stylesheet">
    <link href="/static/css/table.css" rel="stylesheet">
    <link href="/static/css/pages.css" rel="stylesheet">
    <script src="/static/js/jquery-1.10.2.js"></script>
    <script src="/static/js/jquery-ui-1.10.4.custom.js"></script>
    <script src="/static/js/helper.js"></script>
    <script src="/static/js/pages.js"></script>
    <style>
        .branch_line
        {
            background-color: #acdd4a;
        }
        .subbranch_line
        {
            background-color: #9DADC5;
        }
        .branch
        {

        }
        .subbranch
        {

            padding-left: 10px;
        }
        .version
        {
            padding-left: 20px;
        }
        .highlight
        {
            background-color: #e14f1c;
            color: #ffffff;
        }
    </style>
    <script>

        var versionsData=[];
        var isToday=false;

        function highlight(obj)
        {

            var text=$(obj).text();
            $(".highlight").removeClass("highlight");
            if(text){
                $( "td:contains('"+text+"')" ).addClass("highlight");
            }
        }

        function clear_highlight(obj)
        {

            var text=$(obj).text();
            $(".highlight").removeClass("highlight");
        }

        function loadVersions(today){
            cache={};
            isToday=today;
            $.post('getVersionForBrowse.py',{p:pageIndex,keyword:$('#keyword').val(),today:today},
                    function(result,status){
                        if(status == 'success'){
                            if(result.success){
                                html=[];
                                versionsData=result.result;
                                var lastBranch='';
                                var lastSubBranch='';
                                pageIndex=result.pageIndex;
                                pageCount=result.pageCount;
                                for(i in result.result)
                                {
                                    if(result.result[i].branch_name!=lastBranch)
                                    {
                                        lastSubBranch='';
                                        lastBranch=result.result[i].branch_name;
                                        html.push('<tr class="branch_line">');

                                        html.push('<td colspan="2" class="branch">');
                                        html.push(result.result[i].branch_name);
                                        html.push('</td>');

                                        html.push('<td>');
                                        html.push(htmlEncode(result.result[i].branch_desc));
                                        html.push('</td>');

                                        html.push('</tr>');

                                    }
                                    if(result.result[i].subbranch_name!=lastSubBranch)
                                    {
                                        lastSubBranch=result.result[i].subbranch_name;
                                        html.push('<tr class="subbranch_line">');

                                        html.push('<td colspan="2" class="subbranch">');
                                        html.push(result.result[i].subbranch_name);
                                        html.push('</td>');

                                        html.push('<td>');
                                        html.push(htmlEncode(result.result[i].subbranch_desc));
                                        html.push('</td>');

                                        html.push('</tr>');

                                    }
                                    html.push('<tr>');
                                    html.push('<td class="version" onmousemove="highlight(this)" onmouseout="clear_highlight(this)">');

                                    if (result.result[i].has_url)
                                    {
                                        html.push('<a href="'+result.result[i].url+'">');
                                        html.push(result.result[i].version_fullname);
                                        html.push('</a>')
                                    }
                                    else
                                        html.push(result.result[i].version_fullname);
                                    html.push('</td>');

                                    html.push('<td onmousemove="highlight(this)" onmouseout="clear_highlight(this)">');
                                    html.push(result.result[i].version_base);
                                    html.push('</td>');

                                    html.push('<td>');
                                    html.push(htmlEncode(result.result[i].version_desc));
                                    html.push('</td>');


                                    html.push('</tr>');
                                }

                                $('#versionsData').html(html.join(''));
                                showSplitPages();
                            }else{
                            }
                        }
                    });


        }
        function enterKeyLoadVersions(event)
        {
            if(event.which==13){
                loadVersions(false);
            }
        }

        function toPage(index)
        {
            pageIndex=index;
            loadVersions(isToday);
        }
        $(function() {
            $('.mybutton').button();
            $('#keyword').keydown(enterKeyLoadVersions);
            loadVersions(false);
        });
    </script>
</head>
<body>
<h1 style="text-align: center" class="ui-dialog-titlebar">版本浏览</h1>
{% if hasManage %}
    <div style="text-align: right">
        <a href="main.py">管理</a><br/>
        <a href="log.py">发布记录</a>
    </div>
{% endif %}
<hr>
<div style="text-align: center">
    <input type="text" id="keyword" style="width: 60%;"><button class="mybutton" onclick="loadVersions(false);" style="font-size: 13px;">查找</button>
    <button class="mybutton" onclick="loadVersions(true);" style="font-size: 13px;">查找今日版本</button>
</div>
<table border="1" style="width: 100%" >
    <thead>
    <th>版本号</th>
    <th>基于版本号</th>
    <th>说明</th>
    </thead>
    <tbody id="versionsData">

    </tbody>
</table>
<div class="digg" id="pages">
</div>
</body>
</html>